﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntityValue
{
    public static class DynamicExtensions
    {
        public static dynamic ToDynamic(this object value)
        {
            IDictionary<string, object> expando = new ExpandoObject();

            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType()))
                expando.Add(property.Name, property.GetValue(value));

            return expando as ExpandoObject;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            MyDbContext db = new MyDbContext();
            MyEntity e = new MyEntity();
            e["Name"].Value = new StringValue() { Value = "Bình" };
            e["DateOfBirth"].Value = new DateValue() { Value = DateTime.Now };

            YourEntity y = new YourEntity();
            y["Name"].Value = new StringValue() { Value = "Yours" };
            y["DateOfBirth"].Value = new DateValue() { Value = DateTime.Now };
            
            db.MyEntities.Add(e);
            db.YourEntities.Add(y);
            db.SaveChanges();
        }
    }
}
